package com.huc.rest.check;

import com.huc.rest.utils.WebUtils;
import com.huc.rest.vo.ServiceCoreVO;

import javax.servlet.http.HttpServletRequest;

public class HttpHeaderChecks {

    private ServiceCoreVO serviceCoreVO;
    private HttpServletRequest request;

    public static HttpHeaderChecks getInstance(ServiceCoreVO vo,
                                               HttpServletRequest request) {
        HttpHeaderChecks utils = new HttpHeaderChecks();
        utils.serviceCoreVO = vo;
        utils.request = request;
        return utils;
    }

    public void checkRequest(){
        //校验api
        checkAction();
        // 设置请求内容的md5值
        setReqcontentmd5();
    }

    // 设置请求内容的md5值
    private void setReqcontentmd5(){
        String reqcontent = "";
        try{
            reqcontent = WebUtils.getInstance().generateContent(request.getInputStream());
            serviceCoreVO.setReqContent(reqcontent);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    // action内容校验
    private void checkAction() {
        String action = WebUtils.getInstance().getHeaderDecode(request, "action");
        serviceCoreVO.setAction(action);
    }
}
